// ACUAS Microcontroller Board Easy Programming. ATmega16 or ATmega 32


static void set_seed()
//source: http://www.roboternetz.de/wissen/index.php/Zufallszahlen_mit_avr-gcc
{
#ifndef SIMULATION
	unsigned short seed = 0, *p = (unsigned short*) (RAMEND+1);
	extern unsigned short __heap_start;
	while (p >= &__heap_start + 1)
		seed ^= * (--p);
	srandom((unsigned long) seed);
#else
	srandom((unsigned long) 1);
#endif
}

static inline void InitBoard()
{
	DDRA  = 0b00000000; // Input: buttons at port A
	PORTA = 0b11111111; // switch on pull up resistors
#ifdef SIMULATION
	PINA = 0b11111111;  // no button pressed
#endif
	DDRC  = 0b11111111; // Output: LEDs at port C
	PORTC = 0b11111111; // switch off all LEDs
	set_seed();
}

inline static void delay_ds(unsigned char ds)
{
#ifndef SIMULATION
	unsigned char i;
	for(i=0; i<ds; i++)
	{
		uint16_t __ticks = F_CPU / 40; //25000;
		__asm__ volatile (
			"1: sbiw %0,1" "\n\t"
			"brne 1b"
			: "=w" (__ticks)
			: "0" (__ticks)
		);
	}
#endif
}


